package com.dhcc.cdc.busi.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.dao.CdcDictypeMapper;
import com.dhcc.cdc.busi.entity.CdcDictypeEntity;
import com.dhcc.cdc.busi.service.ICdcDictypeService;
import com.dhcc.cdc.sys.entity.CdcDataEntity;
import com.dhcc.cdc.sys.service.ICdcDataService;
import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 业务字典类型表数据服务层接口
 * 
 * @ClassName: CdcDictypeServiceImpl
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:09
 */
@Service("cdcDictypeService")
public class CdcDictypeServiceImpl extends BaseServiceImpl<CdcDictypeMapper, CdcDictypeEntity>
        implements ICdcDictypeService {
    @Autowired
    ICdcDataService dataSrv;

    @Override
    public List<CdcDictypeEntity> page(Page<CdcDictypeEntity> page, Map<String, Object> map) {
        return this.baseMapper.page(page, map);
    }

    @Override
    public List<CdcDictypeEntity> list(Map<String, Object> map) {
        return this.baseMapper.list(map);
    }

    @Override
    public List<CdcDictypeEntity> queryByCode(String dataCode, String typeCode) {
        List<CdcDictypeEntity> result = null;
        String dataId = null;
        if (dataCode != null) {
            dataId = String.valueOf(getDataId(dataCode));
            if (dataId != null) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("dataId", dataId);
                map.put("code", typeCode);
                result = this.baseMapper.list(map);
            }
        }
        return result;
    }

    public Long getDataId(String dataCode) {
        Long dataId = null;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", dataCode);
        CdcDataEntity data = this.dataSrv.list(map).get(0);
        if (data != null) {
            dataId = data.getId();
        }
        return dataId;
    }

}